import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { BasicForm, useForm, FormSchema } from "@/components/Form";
import { create_patient_cond } from "@/api/EmergencyDictionary";
const DetailDrawer = (props: { register: Fn }) => {
	const getTitle = "配置患者健康状态";
	let [patientId, setPatientId] = useState("");
	// let [reloadFun, setReloadFun] = useState();
	let reloadFun: any = null;
	let utilA = "viewComponents.patientInformation";
	const { t } = useTranslation();
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		console.log("打开Drawer", data);
		setPatientId(data.patientId);
		// setReloadFun(data.reload);
		reloadFun = data.reload;
	});

	// 表单
	const formSchema: FormSchema[] = [
		{
			label: t(`${utilA}.height_unit`),
			field: "height",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.weight_unit`),
			field: "weight",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.waistCfr`),
			field: "waistCfr",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.healthIndicators`),
			field: "healthIndicators",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.temperature`), //温度
			field: "temperature",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.respiratory`), //呼吸频率
			field: "respiratory",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.bmiIdx`), //身体质量指数
			field: "bmiIdx",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.chestCfr`), //胸围
			field: "chestCfr",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.hipCfr`), //臀围
			field: "hipCfr",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.chrAlcohol`), //酒精摄入情况
			field: "chrAlcohol",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.chrTobacco`), //烟草使用情况
			field: "chrTobacco",
			component: "Input",
			colProps: { span: 24 }
		},
		{
			label: t(`${utilA}.medAllergy`), //过敏信息
			field: "medAllergy",
			component: "InputTextArea",
			colProps: { span: 24 }
		},
		{
			field: "patCardno",
			component: "InputTextArea",
			colProps: { span: 24 }
		}
	];
	// 配置form
	const [form, { getFieldsValue, resetFields }] = useForm({
		schemas: formSchema,
		showActionButtonGroup: false,
		labelWidth: 120
	});
	const handleSubmit = async () => {
		let value = await getFieldsValue();
		value.patientId = patientId;
		create_patient_cond(value).then(() => {
			closeDrawer();
			resetFields();
			reloadFun();
		});
	};
	return (
		<BasicDrawer {...props} title={getTitle} register={registerDrawer} ok={handleSubmit}>
			<BasicForm register={form} labelWrap={true}></BasicForm>
		</BasicDrawer>
	);
};

export default DetailDrawer;
